<?php
include 'websocker.class.php';
header("Content-Type: text/html; charset=utf-8");
$config=array(
  'address'=>'127.0.0.1',
  'port'=>'8000',
  'event'=>'WSevent',//回调函数的函数名
  'log'=>true,
);
$websocket = new websocket($config);
$websocket->run();  
//$event为服务端事件
/*
    type的类型有三种
    1.in,表示有人进入
    2.out,表示悠然离开
    3.msg表示收到客户端的消息
 */
function WSevent($type,$event){
  global $websocket;
    //roboot($event,'hello');
    $users = $websocket->getUsers();
    $userNumber = count($users);
    var_dump($users);
    var_dump($event['sign']);
    if($userNumber > 1){
      roboot($event['sign'],'已匹配到对手');
    }else{
      roboot($event['sign'],'请等待对手加入');
    }
    $websocket->writeAll('比赛快要开始');
}
 //创建一个回复方法，$sign是用户标识,$t是用户的消息
function roboot($sign,$t){
  global $websocket;
  $websocket->log($sign);
  $websocket->write($sign,$t);
}
?>